package quotation.web.kvStore.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import quotation.R.R;
import quotation.enums.KvStoreEnum;
import quotation.web.kvStore.ddd.entity.KvEntity;
import quotation.web.kvStore.ddd.form.AddKvForm;
import quotation.web.kvStore.ddd.form.UpdateKvForm;
import quotation.web.kvStore.service.KvService;

import javax.validation.Valid;
import java.util.List;

/**
 * @author lyx
 * @date 2025/2/19
 */
@RestController
@RequestMapping("/kv")
@Api(tags = "kv")
public class KvController {

    @Autowired
    private KvService kvService;


    @PostMapping("/add")
    @ApiModelProperty(value = "添加枚举")
    public R add(@RequestBody @Valid AddKvForm form) {

        kvService.add(form);
        return R.success("新增成功");
    }

    @DeleteMapping("/delete")
    @ApiModelProperty(value = "删除枚举")
    public R delete(@RequestParam(value = "id") Long id) {
        kvService.removeById(id);
        return R.success("删除成功");
    }

    @PutMapping("/update")
    @ApiModelProperty(value = "修改枚举")
    public R update(@RequestBody UpdateKvForm form) {
        kvService.update(form);
        return R.success("修改成功");
    }

    @GetMapping("/getAllKv")
    @ApiModelProperty(value = "获取全部枚举")
    public R getAll(@RequestParam(value = "group", required = false) String group) {
        List<KvEntity> allKv = kvService.getAllKv(group);
        return R.success("获取成功", allKv);
    }

    //@GetMapping("/getAllEnum")
    //@ApiModelProperty(value = "获取默认枚举")
    //public R getAllEnum(@RequestParam(value = "group") String group) {
    //    List<KvStoreEnum> allEnum = kvService.getAllEnum(group);
    //    return R.success("获取成功", allEnum);
    //}

}

